package com.youlu.campus.admin.platform;

import com.youlu.campus.entity.PlatformUserComplaint;
import com.youlu.campus.entity.PlatformUserComplaintConsultRecord;
import com.youlu.campus.entity.VO.req.PlatformUserComplaintReadMsgVO;
import com.youlu.campus.service.platform.PlatformUserComplaintConsultRecordService;
import com.youlu.campus.service.platform.PlatformUserComplaintService;
import com.yuelin.infrastructure.quantum.common.QResult;
import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
public class PlatformUserComplaintConsultRecordController {
    @Autowired
    private PlatformUserComplaintConsultRecordService platformUserComplaintConsultRecordService;
    @Lazy
    @Autowired
    private PlatformUserComplaintService platformUserComplaintService;

    /**
     * 平台投诉
     *
     * @return
     */
    @PostMapping("/platform/user-complaint/record/create")
    public QResult create(@RequestBody @NonNull PlatformUserComplaintConsultRecord req) {
        req.setCreateType("system");
        return QResult.success(platformUserComplaintConsultRecordService.create(req));
    }

    @GetMapping("/platform/user-complaint/record/find")
    public QResult findAll(@RequestParam("pucId") String pucId) {
        PlatformUserComplaint u = new PlatformUserComplaint();
        u.setPlatformHasMsg(Boolean.FALSE);
        platformUserComplaintService.update(u);
        return QResult.success(platformUserComplaintConsultRecordService.findByPlatformUserComplaintId(pucId));
    }

    @PostMapping("/platform/user-complaint/record/read")
    public QResult readMsg(@RequestBody @NonNull PlatformUserComplaintReadMsgVO req) {
        req.setCreateType("visitor");
        req.setDate(new Date());
        return QResult.success(platformUserComplaintConsultRecordService.readMsg(req));
    }
}
